const express = require('express')
const router = express.Router()
const json = require('../db/list.json')
const city = require('../city.json')
const searchLabel = require("../db/searchLabel.json");
const conditioneZero = require("../db/condition0.json");
const contitionOne = require("../db/condition1.json");
const contitionTwo = require("../db/condition2.json");
const screenSearchMan = require("../db/screenSearchMan.json");
const screenSearchWomen = require("../db/screenSearchWomen.json");
const bannerVia = require("../db/bannerVia.json");

const loginData = [{
    token:"12324234wosjko",
    info:{
      createTime:2021-04-17,
      from:["江西","南昌","青山湖区"],
      tall:'185',
      xueli:"benke",
      money:'20000',
      phone:'15079120732',
      password:'123456wo',
      userName:'用户15079102732',
      imgUrl:"https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1287948899,1210354170&fm=26&gp=0.jpg"
    }
}]
router.get('/get', (req, res) => {
    res.json(json)
})
router.get('/city', (req, res) => {
    res.json(city)
   
})
// 搜索标签数据
router.get(`/condition/${0}`, (req, res) => {
    res.json(conditioneZero);
  });
  router.get(`/condition/${1}`, (req, res) => {
    res.json(contitionOne);
  });
  router.get(`/condition/${2}`, (req, res) => {
    res.json(contitionTwo);
  });
  router.get("/searchLabel", (req, res) => {
    res.json(searchLabel);
  });
  router.get("/searchLabel", (req, res) => {
    res.json(searchLabel);
  });
  router.get("/screenSearchMan", (req, res) => {
    res.json(screenSearchMan);
  });
  router.get("/screenSearchWomen", (req, res) => {
    res.json(screenSearchWomen);
  });
  // 轮播头像
  router.get("/bannerVia", (req, res) => {
    res.json(bannerVia);
  });

  router.get('/userBaseInfo',(req,res)=>{
      res.send(city.data.cityList)
  })
  router.post('/toHome',(req,res)=>{
    const {phone,password,money,xueli,tall} = req.body
    console.log(phone);
     const personalInfo =  loginData.find(item =>
          item.info.phone === phone
      )
      console.log(personalInfo);
      if(personalInfo){
        res.send({info:"用户信息已注册"})
        res.status(200)
      }else{
        const content = {
          token:Date.now(),
          createTime:Date.now(),
          info:{
            phone,
            password,
            money,
            xueli,
            tall
          }
        }
        loginData.push(content)
        res.send({info:"注册成功",code:'200',data:content})
        res.status(200)
    }
    
    

  })
  router.post('/toIndex',(req,res)=>{
    const {phone,password} = req.body
    console.log(phone,loginData);
    const personalInfo =  loginData.find(item =>
      item.info.phone === phone
  )
  
  console.log(personalInfo);
  if(!personalInfo){res.send({info:"没有该用户",code:'200'}) }
  if(personalInfo.info.password ===password){
    res.send({info:"登录成功",code:'200',data:personalInfo})
  }else{
    res.send({info:"登录失败",code:'200',data:"无数据"})
  }
})
module.exports = router